/*
 * @lc app=leetcode.cn id=783 lang=javascript
 *
 * [783] 二叉搜索树节点最小距离
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var minDiffInBST = function(root) {
   let res=[]
   let dfs=function(node){
       if(!node)return 
       dfs(node.left)
       res.push(node.val)
       dfs(node.right)
   }
   dfs(root)
   let min=Infinity
   for(let i=0;i<res.length-1;i++){
    min=Math.min(res[i+1]-res[i],min)
   }
   return min
};
// @lc code=end

